package com.example.demo.controller;

import com.example.demo.dao.FansDao;
import com.example.demo.dao.YYQXDao;
import com.example.demo.pojo.YYQX;
import com.example.demo.pojo.fans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;

@Controller
public class fansController {
    //应该是service
    @Autowired
    FansDao fansDao;
    @Autowired
    YYQXDao yyqxDao;
    //只要请求fans就会到list中
    @RequestMapping("/fans")
    public String list(Model model){
        Collection<fans> fansAll = fansDao.getAll();
        model.addAttribute("fans",fansAll);
        return "fans/list";
    }
    @GetMapping("/add")
    public String addfansPage(Model model){
        //查询所有部门信息
        Collection<YYQX> yyqxhobbys = yyqxDao.getYyqxhobbys();
        model.addAttribute("yyqxhobbys",yyqxhobbys);
        return "fans/add";
    }
    @PostMapping("/add")
    public String addfans(fans fan){
        //查询所有部门信息
        /*Collection<YYQX> yyqxhobbys = yyqxDao.getYyqxhobbys();
        model.addAttribute("yyqxhobbys",yyqxhobbys);*/
        //添加成功之后跳回原来的员工页面
        System.out.println("Debug"+fan);
        fansDao.save(fan);
        return "redirect:/fans";
    }
}
